class Solution {
public:
    int longestOnes(vector<int>& nums, int k) {
        int right=0;
        int left=0;
        int ret=0;
        int zero=0;
        int n=nums.size();
        while(right<n)
        {
            if(nums[right]==0)
            {
                zero++;
            }
            if(zero<=k)
            {
                ret=max(ret,right-left+1);
            }
            while(zero>k)
            {
                
                if(nums[left]==0)
                {
                    zero--;
                }
                left++;
            }
            ++right;
        }
        return ret;
    }
};
